#include <iostream>
#include <string>
#include <algorithm>
#define MAXX 100005
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string a;
    cin >> a;
    int b[MAXX], k = 0;
    b[0] = -1;
    for (int i = 0; i < n; i++)
    {
        int w = a[i] - 'A' + 1;
        if (w >= b[k])
            b[++k] = w;
        else
        {
            //二分查找到w的位置
            int q = upper_bound(b, b + k, w) - b;
            b[q] = w;
        }
    }
    cout << n - k << endl;
    return 0;
}